#include "rclcpp/rclcpp.hpp"
#include "rclcpp/timer.hpp"
#include <chrono>

using namespace std::chrono_literals;
//目的：加插定时器之间会不会相互阻塞
class MultiTimerNode : public rclcpp::Node {
public:
  MultiTimerNode(const rclcpp::NodeOptions &options)
      : Node("component_multi_timer_node", options) {
    RCLCPP_INFO(this->get_logger(),
                "Start up node :component_multi_timer_node");
    timer1_ = this->create_wall_timer(
        1s, std::bind(&MultiTimerNode::timer1_callback, this));
    timer2_ = this->create_wall_timer(
        3s, std::bind(&MultiTimerNode::timer2_callback, this));
  }
  void timer1_callback() {
    // RCLCPP_INFO(this->get_logger(), "timer1 thread pid is %d", gettid());
    // RCLCPP_INFO(this->get_logger(), "timer1 sleep for 5s...");
    // rclcpp::sleep_for(3s);
    RCLCPP_INFO(this->get_logger(), "Timer 1 callback");
  }
  void timer2_callback() {
    // RCLCPP_INFO(this->get_logger(), "timer2 thread pid is %d", gettid());
    // RCLCPP_INFO(this->get_logger(), "timer2 sleep for 5s...");
    // rclcpp::sleep_for(3s);
    RCLCPP_INFO(this->get_logger(), "Timer 2 callback");
  }

private:
  rclcpp::TimerBase::SharedPtr timer1_;
  rclcpp::TimerBase::SharedPtr timer2_;
};

#include "rclcpp_components/register_node_macro.hpp"
RCLCPP_COMPONENTS_REGISTER_NODE(MultiTimerNode)
